<%@ page pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/base/taglibs.jsp"%>

<html>
	<head>
		<link href="${ctx}/css/main.css" rel="stylesheet" type="text/css" />
	</head>
	<script type="text/javascript" src="${ctx}/js/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="${ctx}/js/xhEditor/jquery-1.4.2.min.js"></script>
	<script type="text/javascript" src="${ctx}/js/xhEditor/xheditor-zh-cn.min.js"></script>
	<script language="javascript">
		function submitAction(action){
			prodForm.action = action ;
			prodForm.submit();
		}
		
		function init(){
			document.getElementById("prodName").value = "";
			document.getElementById("brand").value = "";
			document.getElementById("prodType").value ="";
			document.getElementById("amount").value = "";
			document.getElementById("unit").value = "";
			document.getElementById("prodLevel").value = "";
			document.getElementById("price").value = "";
			document.getElementById("userId").value ="";
			document.getElementById("userName").value ="";
			document.getElementById("endDate").value ="";
			document.getElementById("prodDesc").value ="";
			document.getElementById("contactName").value ="";
			document.getElementById("contactTel").value ="";
			document.getElementById("contactMobile").value ="";
			document.getElementById("infoCategory").value ="";
		}  
		
		function saveNewProduct(action){
			var prodName= document.getElementById("prodName").value;	
			var prodType= document.getElementById("prodType").value;
			var price = document.getElementById("price").value ;
			var userId= document.getElementById("userId").value ;
			var contactName= document.getElementById("contactName").value ;
			var contactTel= document.getElementById("contactTel").value ;
			var contactMobile= document.getElementById("contactMobile").value ;
			var endDate= document.getElementById("endDate").value ;
			if(prodName==''){alert('请输入商品名称');return;}
			if(prodType==''|| (prodType==null)){alert('请选择商品种类');return;}
			if(userId==''){alert('请输入商品所有者');return;}
			if(price==''){alert('请输入商品价格');return;}
			if(endDate==''){alert('请输入截止时间');return;}
			if(!validateNumber()) return;
			if(contactName==''){alert('请输入联系人');return;}
			if(contactTel=='' && contactMobile==''){alert('联系电话和联系手机至少填一个');return;}
			submitAction(action);
	    } 
	    
	    function doDelete(action,id){
			if(confirm('是否确认删除？')){
				location.href = "${ctx}/" + action + "?id=" + id;
			}
		}
		
		var detail;
		
		function searchUserInfo() {
			if(!detail || detail.closed) {
				detail = window.open("about:blank", "prod_owner_choose", "status,scrollbars,resizable=no,left=190,top=150,width=750,height=600");
			}
			ownerForm.target = "prod_owner_choose";
			ownerForm.submit();
			detail.focus();
		}
		
		function validateNumber() {
			var price = document.getElementById("price").value;
			if(isNaN(price)) {
				alert('商品价格只能为数字');
				return false;
			}
			if(price.indexOf('-') > -1) {
			   alert('商品价格不能为负数');
			   return false;
			}
			return true;
		}
		
		function clickFile(action, fileName, type){
			location.href = "${ctx}/" + action + "?fileName=" + fileName + "&type=" + type;
		}
		
		function validateFileType(name) {
			fileName = document.getElementById(name).value;
			fileType = fileName.substr(fileName.lastIndexOf(".")).toLowerCase(); 
			if(fileType != '.jpg' && fileType != '.png' && fileType != '.jpeg' && fileType != '.gif' && fileType != '.bmp'){
				alert('图片文件类型错误');
				document.getElementById(name).outerHTML = document.getElementById(name).outerHTML;
				return false;
			}
		}
	</script>
	<body>
		<form name="ownerForm" id="ownerForm" method="post" action="searchProdOwner.ac"></form>
		<form name="prodForm" id="prodForm" method="post" action="" ENCTYPE="multipart/form-data">
			<table border="0" cellspacing="1" cellpadding="3" align="center" width="100%">
				<tr>
					<td class="td11" align="left" colspan="4">
					<c:if test="${!empty product.id}">
						<input type="button" name="saveOld" value="保存" onClick="saveNewProduct('prodUpdate.ac');">
						&nbsp;&nbsp;<input type="button" name="delete" value="删除" onClick="doDelete('deleteProd.ac', '${product.id}');">
					</c:if>	
					<c:if test="${empty product.id}">
						<input type="button" name="saveNew" value="保存" onClick="saveNewProduct('prodSave.ac');">
						&nbsp;&nbsp;<input type="button" name="reset" value="重置" onClick="init()">
					</c:if>	
						&nbsp;&nbsp;<input type="button" name="back" value="返回" onClick="submitAction('backToProdFind.ac');">	
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2"> 
						商品名称 <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						<input type="hidden" name="id" value="${product.id}">
						<input type="hidden" name="fileName" value="${product.fileName}">
						<input type="hidden" name="brandPic" value="${product.brandPic}">
						<input type="text" name="prodName" size="32" value="${product.prodName}">
					</td>
					<td width="20%" class="td2"> 
						 信息类别 <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						<select name="infoCategory" style="width:200px">
				    		<c:if test="${product.infoCategory != 2}"> 
				    			<option value="1" selected="selected">出售</option>
				    			<option value="2" >求购</option>
				    		</c:if>
				    		<c:if test="${product.infoCategory == 2}">
				    			<option value="1" >出售</option>
				    			<option value="2" selected="selected">求购</option>
				   			</c:if>
					   	</select>
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2"> 
						 商品所有者 <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						<input type="hidden" name="userId" value="${product.userId}"/>
						<input readonly="readonly" type="text" name="userName" size="28" value="${product.userName}">
						<img onclick="searchUserInfo()" src="${ctx}/images/index/search.gif" width="16" height="16" align="absmiddle">
					</td>
					<td width="20%" class="td2">
						商品种类 <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
					  	<select name="prodType" style="width:200px">
					    	<c:forEach var="kindTypeCode" items="${sessionScope.T_kindTypeList}">
					    		<c:if test="${kindTypeCode.typeCode == product.prodType}"> 
					    			<option value="${kindTypeCode.typeCode}" selected="selected">${kindTypeCode.typeName}</option>
					    		</c:if>
					    		<c:if test="${kindTypeCode.typeCode != product.prodType}">
					    			<option value="${kindTypeCode.typeCode}">${kindTypeCode.typeName}</option>
					   			</c:if>
							</c:forEach>
					   	</select>
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2"> 
						 商品价格 <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						<input type="text" style="text-align:right" name="price" size="32" value="${product.price}" onblur="validateNumber();">
					</td>
					<td width="20%" class="td2"> 
						商品品牌
					</td>
					<td width="30%" class="td2">
						<select name="brand" style="width:200px">
						    <c:forEach var="bdTypeCode" items="${sessionScope.T_bdTypeList}">
						    <c:if test="${bdTypeCode.typeCode == product.brand}"> 
						    	<option value="${bdTypeCode.typeCode}" selected="selected">${bdTypeCode.typeName}</option>
						    </c:if>
						    <c:if test="${bdTypeCode.typeCode != product.brand}">
						    	<option value="${bdTypeCode.typeCode}">${bdTypeCode.typeName}</option>
						    </c:if>
							</c:forEach>
					    </select>
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2"> 
						截止时间 <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						<input size="28" readonly="readonly" id="endDate" type="text" name="endDate" value="${product.endDate}"/>
						<img onclick="WdatePicker({el:'endDate'})" src="${ctx}/js/My97DatePicker/skin/datePicker.gif" width="16" height="22" align="absmiddle">
					</td>
					<td width="20%" class="td2"> 
						商品等级
					</td>
					<td width="30%" class="td2">
						<select name="prodLevel" style="width:200px">
						    <c:forEach var="rkTypeCode" items="${sessionScope.T_rkTypeList}">
							    <c:if test="${rkTypeCode.typeCode == product.prodLevel}"> 
							    	<option value="${rkTypeCode.typeCode }" selected="selected">${rkTypeCode.typeName}</option>
							    </c:if>
							    <c:if test="${rkTypeCode.typeCode != product.prodLevel}">
							    	<option value="${rkTypeCode.typeCode}">${rkTypeCode.typeName}</option>
							    </c:if>
							</c:forEach>
						</select>	
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2"> 
						 商品数量
					</td>
					<td width="30%" class="td2">
						<input type="text" name="amount" size="32" value="${product.amount}" onkeydown="if(event.keyCode==13)event.keyCode=9" onKeyPress="if ((event.keyCode <48 || event.keyCode>57)) event.returnValue=false">
					</td>
					<td width="20%" class="td2"> 
						商品单位
					</td>
					<td width="30%" class="td2">
						<select name="unit" style="width:200px">
						    <c:forEach var="unitTypeCode" items="${sessionScope.T_unitTypeCodeList}">
							    <c:if test="${unitTypeCode.typeCode == product.unit}"> 
							    	<option value="${unitTypeCode.typeCode}" selected="selected">${unitTypeCode.typeName}</option>
							    </c:if>
							    <c:if test="${unitTypeCode.typeCode != product.unit}">
							    	<option value="${unitTypeCode.typeCode}">${unitTypeCode.typeName}</option>
							    </c:if>
							</c:forEach>
						</select>
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2"> 
						联系人 <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						 <input type="text" name="contactName" size="32" value="${product.contactName}">		
					</td>
					<td width="20%" class="td2"> 
						热门标志
					</td>
					<td width="30%" class="td2">
						<c:if test="${product.hotFlag == '1'}">
						 	<input type="checkbox" checked="checked" name="hotFlag" size="32" value="1">
						</c:if>	
						<c:if test="${product.hotFlag != '1'}">
						  	<input type="checkbox"  name="hotFlag" size="32" value="1">
						</c:if>
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2"> 
						联系电话 <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						 <input type="text" name="contactTel" size="32" value="${product.contactTel}">
					</td>
					<td width="20%" class="td2"> 
						联系手机 <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						 <input type="text" name="contactMobile" size="32" value="${product.contactMobile}">	
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2">
						产品图片上传
					</td>
					<td width="20%" class="td2" colspan="3">
						<input type="file" name="prodFile" size="40" value="" onchange="validateFileType('prodFile');">
						<span style="color:red;vertical-align:middle;">&nbsp;&nbsp;&nbsp;&nbsp;图片必须是以jpg,gif,jpeg,png,bmp为后缀文件</span>
					</td>
				</tr>
				<tr>
					<td width="10%" class="td2">  
						产品图片
					</td>
					<td width="30%" class="td2" colspan="3">
						<a href="javascript:clickFile('getProdPhoto.ac','${product.fileName}', 'prod');">${product.fileName}</a>
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2">
						品牌图片上传
					</td>
					<td width="20%" class="td2" colspan="3">
						<input type="file" name="brandFile" size="40" value="" onchange="validateFileType('brandFile');">
						<span style="color:red;vertical-align:middle;">&nbsp;&nbsp;&nbsp;&nbsp;图片必须是以jpg,gif,jpeg,png,bmp为后缀文件</span>
					</td>
				</tr>
				<tr>
					<td width="10%" class="td2">  
						品牌图片
					</td>
					<td width="30%" class="td2" colspan="3">
						<a href="javascript:clickFile('getProdPhoto.ac','${product.brandPic}', 'brand');">${product.brandPic}</a>
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2"> 
						产品归属地
					</td>
					<td width="30%" class="td2" colspan="3"> 
						<input type="text" name="prodPlace" value="${product.prodPlace}">	
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2"> 
						产品简介
					</td>
					<td width="30%" class="td2" colspan="3"> 
						<textarea rows="4" cols="75" name="summary" >${product.summary}</textarea>
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2"> 
						质量说明
					</td>
					<td width="30%" class="td2" colspan="3"> 
						<textarea rows="4" cols="75" name="qualityDesc" >${product.qualityDesc}</textarea>
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2"> 
						规格描述
					</td>
					<td width="30%" class="td2" colspan="3"> 
						<textarea rows="4" cols="75" name="standardDesc" >${product.standardDesc}</textarea>
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2"> 
						商品描述
					</td>
					<td width="30%" class="td2" colspan="3"> 
						<textarea rows="6" cols="75" name="prodDesc" >${product.prodDesc}</textarea>
					</td>
				</tr>
			</table>
		</form>
	</body>	
</html>